<template>
  <div class="login">
    <img src="@/assets/img/wave-01.png" alt="" class="wave" />
    <div class="container">
      <div class="img">
        <img src="@/assets/img/phone.png" alt="" />
      </div>
      <div class="login-container">
        <div class="form-login">
          <img class="avatar" src="@/assets/img/profile.png" alt="" />
          <h2>后台登录</h2>
          <div class="input-div one">
            <div class="i">
              <i class="iconfont icon-username" aria-hidden="true"> </i>
            </div>
            <div>
              <input
                v-model="form.username"
                placeholder="用户名"
                class="input"
                type="text"
              />
            </div>
          </div>
          <div class="input-div pass">
            <div class="i">
              <i class="iconfont icon-password" aria-hidden="true"> </i>
            </div>
            <div class="div">
              <input
                v-model="form.password"
                placeholder="密码"
                class="input"
                type="password"
              />
            </div>
          </div>
          <button @click="login" class="btn">登陆</button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "Login",
  data() {
    return {
      form: {
        username: "",
        password: ""
      }
    };
  },
  methods: {
    async login() {
      const username = this.form.username;
      const password = this.form.password;
      if (username == "" || password == "") {
        this.$message.error("请完善登陆信息");
        return;
      }
      const { data: res } = await this.$api.user.login({
        username,
        password
      });
      if (res.code === 400) {
        this.$message.error(res.msg);
        this.form.username = "";
        this.form.password = "";
        return;
      }
      this.$message.success(res.msg);
      const token = res.data;
      this.$store.commit("setToken", token);
      this.$router.replace("/adminDJ");
    }
  }
};
</script>
<style lang="scss" scoped>
.wave {
  position: fixed;
  height: 100%;
  left: 0;
  bottom: 0;
  z-index: -1;
}

.container {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-gap: 7rem;
  padding: 0 2rem;
}

.img {
  display: flex;
  justify-content: flex-end;
  align-items: center;

  img {
    width: 400px;
  }
}

.login-container {
  display: flex;
  align-items: center;
  text-align: center;

  h2 {
    font-size: 24px;
    margin: 8px 0;
    font-weight: 700;
  }
}

div.form-login {
  width: 290px;

  .avatar {
    width: 100px;
  }
  h2 {
    font-size: 26px;
    text-transform: uppercase;
    margin: 15px 0;
    color: #333;
  }
}

.input-div > div {
  position: relative;
  height: 45px;
}

.input-div > div h5 {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
  font-size: 18px;
  transition: 0.3s;
}

.input {
  position: absolute;
  outline: 0;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  border: none;
  background: none;
  padding: 0.5rem 0.7rem;
  font-size: 1.2rem;
  color: #555;
  font-family: "Source Sans Pro", sans-serif;
  font-weight: 700;
}

.input-div {
  position: relative;
  display: grid;
  grid-template-columns: 7% 93%;
  margin: 25px 0;
  padding: 5px 0;
  text-decoration: none;
  outline: none;
}

.btn {
  display: block;
  width: 100%;
  height: 40px;
  border-radius: 25px;
  text-transform: uppercase;
  background-color: #6b5cff;
  color: white;
  border: none;
  letter-spacing: 1px;
  margin-top: 20px;
  transition: 0.5s;
  font-weight: 700;
  cursor: pointer;
  font-size: 16px;
}

.i {
  display: flex;
  justify-content: center;
  align-items: center;
  i {
    color: #d9d9d9;
    transition: 0.3s;
  }

  .icon-username {
    font-size: 20px;
  }
}
</style>
